package com.yshkj.payment.controller.medicinal;

import com.yshkj.payment.dto.CommonJsonDto;
import com.yshkj.payment.dto.DeleteJsonDto;
import com.yshkj.payment.dto.MedicinalFormDto;
import com.yshkj.payment.dto.MedicinalListDto;
import com.yshkj.payment.service.MedicinalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by 唐旭 on 2016/10/2.
 */
@Controller
@RequestMapping("/medicinal")
public class MedicinalController {

    @Autowired
    private MedicinalService medicinalService;

    @RequestMapping("/list")
    @ResponseBody
    public MedicinalListDto list(MedicinalListDto listDto) {
        medicinalService.loadList(listDto);
        return listDto;
    }

    @RequestMapping("/delete")
    @ResponseBody
    public DeleteJsonDto delete(@RequestBody String uuid) {
        return medicinalService.delete(uuid);
    }

    @RequestMapping(value = "/edit", method = RequestMethod.GET)
    @ResponseBody
    public MedicinalFormDto edit(String uuid) {
        return medicinalService.load(uuid);
    }

    @RequestMapping(value = "/edit", method = RequestMethod.POST)
    @ResponseBody
    public CommonJsonDto edit(@RequestBody MedicinalFormDto formDto) {
        return medicinalService.update(formDto);
    }
}
